package cn.stylefeng.guns.modular.rest.aop;

import cn.stylefeng.guns.sys.core.constant.JwtConstants;
import cn.stylefeng.guns.sys.core.util.JwtTokenUtil;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.util.HttpContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Data:2020/9/9 15:50
 * @Author:WZ
 */
@Service
public class UserAop {

    @Autowired
    private  UserService userService;

    public  User getUser() {
        HttpServletRequest request = HttpContext.getRequest();
        // 然后根据token获取用户登录信息，这里省略获取用户信息的过程
        final String requestHeader = request.getHeader(JwtConstants.AUTH_HEADER);
        String authToken;
        authToken = requestHeader.substring(7);
        Long userid = Long.valueOf(JwtTokenUtil.getUsernameFromToken(authToken));
        User user = userService.getById(userid);
        return user;
    }
}
